home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
ZSI
/
twisted
/
client.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
9KB
|
279 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import time
from zope.interface import classProvides, implements, Interface
from twisted.web import client
from twisted.internet import defer
from twisted.internet import reactor
from twisted.python import log
from twisted.python.failure import Failure
from ZSI.parse import ParsedSoap
from ZSI.writer import SoapWriter
from ZSI.fault import FaultFromFaultMessage
from ZSI.wstools.Namespaces import WSA
from WSresource import HandlerChainInterface, CheckInputArgs
class HTTPPageGetter(client.HTTPPageGetter):
def handleStatus_500(self):
log.err('HTTP Error 500')
def handleStatus_404(self):
log.err('HTTP Error 404')
client.HTTPClientFactory.protocol = HTTPPageGetter
def getPage(url, contextFactory = None, *args, **kwargs):
(scheme, host, port, path) = client._parse(url)
factory = client.HTTPClientFactory(url, *args, **kwargs)
if scheme == 'https':
if contextFactory is None:
raise RuntimeError, 'must provide a contextFactory'
conn = reactor.connectSSL(host, port, factory, contextFactory)
else:
conn = reactor.connectTCP(host, port, factory)
return factory
class ClientDataHandler:
classProvides(HandlerChainInterface)
readerClass = None
writerClass = None
def processResponse(cls, soapdata, **kw):
if len(soapdata) == 0:
raise TypeError('Received empty response')
ps = ParsedSoap(soapdata, readerclass = cls.readerClass)
if ps.IsAFault() is True:
log.msg('Received SOAP:Fault', debug = True)
raise FaultFromFaultMessage(ps)
return ps
processResponse = classmethod(processResponse)
def processRequest(cls, obj, nsdict = { }, header = True, **kw):
tc = None
if kw.has_key('requesttypecode'):
tc = kw['requesttypecode']
elif kw.has_key('requestclass'):
tc = kw['requestclass'].typecode
else:
tc = getattr(obj.__class__, 'typecode', None)
sw = SoapWriter(nsdict = nsdict, header = header, outputclass = cls.writerClass)
sw.serialize(obj, tc)
return sw
processRequest = classmethod(processRequest)
class WSAddressHandler:
implements(HandlerChainInterface)
uri = WSA.ADDRESS
def processResponse(self, ps, wsaction = None, soapaction = None, **kw):
addr = self.address
addr.parse(ps)
action = addr.getAction()
if not action:
raise WSActionException('No WS-Action specified in Request')
if not soapaction:
return ps
soapaction = soapaction.strip('\'"')
if soapaction and soapaction != wsaction:
raise WSActionException('SOAP Action("%s") must match WS-Action("%s") if specified.' % (soapaction, wsaction))
return ps
def processRequest(self, sw, wsaction = None, url = None, endPointReference = None, **kw):
Address = Address
import ZSI.address
if sw is None:
self.address = None
return None
if not sw.header:
raise RuntimeError, 'expecting SOAP:Header'
self.address = addr = Address(url, wsAddressURI = self.uri)
addr.setRequest(endPointReference, wsaction)
addr.serialize(sw, typed = False)
return sw
class DefaultClientHandlerChain:
def __init__(self, *handlers):
self.handlers = handlers
self.debug = len(log.theLogPublisher.observers) > 0
self.flow = None
__init__ = CheckInputArgs(HandlerChainInterface)(__init__)
def parseResponse(ps, replytype):
return ps.Parse(replytype)
parseResponse = staticmethod(parseResponse)
def processResponse(self, arg, replytype, **kw):
if self.debug:
log.msg('--->PROCESS REQUEST\n%s' % arg, debug = 1)
for h in self.handlers:
arg.addCallback(h.processResponse, **kw)
arg.addCallback(self.parseResponse, replytype)
def processRequest(self, arg, **kw):
if self.debug:
log.msg('===>PROCESS RESPONSE: %s' % str(arg), debug = 1)
if arg is None:
return None
for h in self.handlers:
arg = h.processRequest(arg, **kw)
s = str(arg)
if self.debug:
log.msg(s, debug = 1)
return s
class DefaultClientHandlerChainFactory:
protocol = DefaultClientHandlerChain
def newInstance(cls):
return cls.protocol(ClientDataHandler)
newInstance = classmethod(newInstance)
class WSAddressClientHandlerChainFactory:
protocol = DefaultClientHandlerChain
def newInstance(cls):
return cls.protocol(ClientDataHandler, WSAddressHandler())
newInstance = classmethod(newInstance)
class Binding:
agent = 'ZSI.twisted client'
factory = DefaultClientHandlerChainFactory
defer = False
def __init__(self, url = None, nsdict = None, contextFactory = None, tracefile = None, **kw):
self.url = url
if not nsdict:
pass
self.nsdict = { }
self.contextFactory = contextFactory
self.http_headers = {
'content-type': 'text/xml' }
self.trace = tracefile
def addHTTPHeader(self, key, value):
self.http_headers[key] = value
def getHTTPHeaders(self):
return self.http_headers
def Send(self, url, opname, pyobj, nsdict = { }, soapaction = None, chain = None, **kw):
if not url:
pass
url = self.url
cookies = None
if chain is not None:
cookies = chain.flow.cookies
d = { }
d.update(self.nsdict)
d.update(nsdict)
if soapaction is not None:
self.addHTTPHeader('SOAPAction', soapaction)
chain = self.factory.newInstance()
soapdata = chain.processRequest(pyobj, nsdict = nsdict, soapaction = soapaction, **kw)
if self.trace:
print >>self.trace, '_' * 33, time.ctime(time.time()), 'REQUEST:'
print >>self.trace, soapdata
f = getPage(str(url), contextFactory = self.contextFactory, postdata = soapdata, agent = self.agent, method = 'POST', headers = self.getHTTPHeaders(), cookies = cookies)
if isinstance(f, Failure):
return f
chain.flow = f
self.chain = chain
return chain
def Receive(self, replytype, chain = None, **kw):
if not chain:
pass
chain = self.chain
d = chain.flow.deferred
if self.trace:
def trace(soapdata):
print >>self.trace, '_' * 33, time.ctime(time.time()), 'RESPONSE:'
print >>self.trace, soapdata
return soapdata
d.addCallback(trace)
chain.processResponse(d, replytype, **kw)
if self.defer:
return d
failure = []
append = failure.append
def errback(result):
append(result)
d.addErrback(errback)
while not d.called:
reactor.runUntilCurrent()
t2 = reactor.timeout()
if reactor.running:
pass
t = t2
reactor.doIteration(t)
continue
(None,)
pyobj = d.result
if len(failure):
failure[0].raiseException()
return pyobj
def trace():
if trace:
print >>trace, '_' * 33, time.ctime(time.time()), 'RESPONSE:'
for i in (self.reply_code, self.reply_msg):
print >>trace, str(i)
print >>trace, '-------'
print >>trace, str(self.reply_headers)
print >>trace, self.data